package hfdp.chp08.chp0802;

public abstract class CaffeineBeverageWithHook {

    /**
     * template method.
     * It serves as a template for an algorithm, in this case,
     * an algorithm for making caffeinated beverages.
     * In the template, each step of the algorithm is represented by a method.
     */
    final void prepareRecipe(){
        boilWater();
        brew();
        pourInCup();
        if (customerWantsCondiments()){
            addCondiments();
        }
    }

    void boilWater(){
        System.out.println("Boiling water");
    }

    void pourInCup(){
        System.out.println("Pouring into cup");
    }

    /**
     * Because Coffee and Tea handle these methods in different ways, they’re going to have to
     * be declared as abstract. Let the subclasses worry about that stuff!
     */
    abstract void brew();

    abstract void addCondiments();

    /**
     * This is a hook because the subclass can override this method, but doesn’t have to.
     * @return
     */
    boolean customerWantsCondiments(){
        return true;
    }
}
